import json
import sys

def rename_window_elements(file_path):
    # 读取JSON文件
    with open(file_path, 'r', encoding='utf-8') as f:
        data = json.load(f)
    
    # 修改FrontJson数组中的元素
    if 'FrontJson' in data and isinstance(data['FrontJson'], list):
        for item in data['FrontJson']:
            if 'name' in item and isinstance(item['name'], str) and item['name'].startswith('window_'):
                # 将window_开头的名称改为w_开头
                item['name'] = 'w_' + item['name'][7:]
    
    # 写回修改后的JSON文件
    with open(file_path, 'w', encoding='utf-8') as f:
        json.dump(data, f, ensure_ascii=False, indent=4)

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python rename_window_elements.py <file_path>")
        sys.exit(1)
    
    file_path = sys.argv[1]
    rename_window_elements(file_path)
    print(f"Successfully renamed elements in {file_path}")